import 'package:flutter/material.dart';
import 'dart:io' show Platform;
import 'package:flutter/services.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: Page1(),
    );
  }
}

class Page1 extends StatelessWidget {
  const Page1({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Page 1')),
      body: Center(
        child: ElevatedButton(
          child: const Text('跳转到 Page 2'),
          onPressed: () {
            Navigator.push(
              context,
              MaterialPageRoute(builder: (_) => const Page2()),
            );
          },
        ),
      ),
    );
  }
}

class Page2 extends StatefulWidget {
  const Page2({super.key});

  @override
  State<Page2> createState() => _Page2State();
}

class _Page2State extends State<Page2> {
  @override
  void dispose() {
    debugPrint('Page2 disposed');
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Page 2'),
        leading: IconButton(
          icon: const Icon(Icons.arrow_back),
          onPressed: () {
            Navigator.pop(context);
          },
        ),
      ),
      body: Center(
        child: Platform.isIOS
            ? const SizedBox(
          width: 300,
          height: 200,
          child: UiKitView(
            viewType: 'native-text-view',
            creationParams: {
              'text': '这是iOS原生控件',
            },
            creationParamsCodec: StandardMessageCodec(),
          ),
        )
            : const SizedBox(
          width: 300,
          height: 200,
          child: AndroidView(
            viewType: 'native-text-view',
            creationParams: {
              'text': '这是Android原生控件',
            },
            creationParamsCodec: StandardMessageCodec(),
          ),
        ),
      ),
    );
  }
}
